<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="">

    <title>主页</title>

    <!-- Bootstrap core CSS -->
    <link href="${basePath}/js/common/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="${basePath}/css/common/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="${basePath}/css/common/dashboard.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="${basePath}/js/common/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="${basePath}/js/common/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="${basePath}/js/common/html5shiv.js"></script>
      <script src="${basePath}/js/common/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
    <#include "/common/top.ftl">

    <div class="container-fluid">
      <div class="row">
        <#include "/common/left.ftl">
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        	<h1 class="page-header">主机管理</h1>
			<form method="post" action="" id="formId" class="form-inline">
				<div class="well">
				  <div class="form-group">
					<input type="text" class="form-control" style="width: 300px;" value="" 
								name="findContent" id="findContent" placeholder="输入ip">
				  </div>
				 <span class=""> 
					<button type="submit" class="btn btn-primary">查询</button>
						<a class="btn btn-success" onclick="$('#addHost').modal();">Add</a>
						<button type="button" id="deleteAll" class="btn  btn-danger">Delete</button>
				 </span>    
				</div>
				<hr>
				<table class="table table-bordered">
					<tr>
						<th><input type="checkbox" id="checkAll"/></th>
						<th>HOST</th>
						<th>GROUP</th>
						<th>USER</th>
						<th>连接方式</th>
						<th>备注</th>
						<th>操作</th>
					</tr>
					<tr>
						<td><input value="4" check='box' type="checkbox" /></td>
						<td>127.0.0.1</td>
						<td>local</td>
						<td>app</td>
						<td>ssh</td>
						<td>应用主机</td>
						<td>
							<i class="glyphicon glyphicon-remove"></i><a href="javascript:deleteById([4]);">删除</a>
						</td>
					</tr>
				</table>
				<div class="pagination pull-right">
					<ul class='pagination'><li class='active'><a href='javascript:void(0);' >1</a></li><li><a href='javascript:;' onclick='_submitform(2)'>2</a></li><li><a href='javascript:;'  onclick='_submitform(2)'>下一页</a></li></ul><script>	function _submitform(pageNo){		$("#formId").append($("<input type='hidden' value='" + pageNo +"' name='pageNo'>")).submit();	}</script>
				</div>
			</form>
        </div>
      </div>
    </div>
	<div class="modal fade" id="addHost" tabindex="-1" role="dialog" aria-labelledby="addHostLabel">
	  <div class="modal-dialog" role="document">
		<div class="modal-content">
		  <div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			<h4 class="modal-title" id="addHostLabel">添加主机</h4>
		  </div>
		  <div class="modal-body">
			<form id="boxRoleForm">
			  <div class="form-group">
				<label for="recipient-name" class="control-label">host:</label>
				<input type="text" class="form-control" name="host" id="host" placeholder="请输入ip"/>
			  </div>
			  <div class="form-group">
				<label for="recipient-name" class="control-label">user:</label>
				<input type="text" class="form-control" name="user" id="user" placeholder="请输入该主机系统用户"/>
			  </div>
			  <div class="form-group">
				<label for="recipient-name" class="control-label">passord:</label>
				<input type="text" class="form-control" name="passord" id="passord" placeholder="请输入该主机系统密码"/>
			  </div>
			  <div class="form-group">
				<label for="recipient-name" class="control-label">group:</label>
				<input type="text" class="form-control" id="group" name="group"  placeholder="请输入组">
			  </div>
			  <div class="form-group">
				<label for="recipient-name" class="control-label">连接方式:</label>
				<input type="text" class="form-control" value="ssh" disabled id="connect" name="connect"  placeholder="请输入连接方式">
			  </div>
			  <div class="form-group">
				<label for="recipient-name" class="control-label">备注:</label>
				<input type="text" class="form-control" id="tip" name="tip"  placeholder="备注">
			  </div>
			</form>
		  </div>
		  <div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
			<button type="button" onclick="addHost();" class="btn btn-primary">Save</button>
		  </div>
		</div>
	  </div>
	</div>
    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="${basePath}/js/common/jquery/jquery1.8.3.min.js"></script>
    <script>window.jQuery || document.write('<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"><\/script>')</script>
    <script src="${basePath}/js/common/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="${basePath}/js/common/ie10-viewport-bug-workaround.js"></script>
    <script src="${basePath}/js/shiro.demo.js"></script>
	<script src="${basePath}/js/common/layer/layer.js"></script>
	<script >
		so.init(function(){
			//初始化全选。
			so.checkBoxInit('#checkAll','[check=box]');
			//全选
			so.id('deleteAll').on('click',function(){
				var checkeds = $('[check=box]:checked');
				if(!checkeds.length){
					return layer.msg('请选择要删除的选项。',so.default),!0;
				}
				var array = [];
				checkeds.each(function(){
					array.push(this.value);
				});
				return deleteById(array);
			});
		});
		function deleteById(ids){
			var index = layer.confirm("确定这"+ ids.length +"个主机？",function(){
				var load = layer.load();
				$.post('${basePath}/config/del.shtml',{ids:ids.join(',')},function(result){
					layer.close(load);
					if(result && result.status != 200){
						return layer.msg(result.message,so.default),!0;
					}else{
						layer.msg(result.resultMsg);
						setTimeout(function(){
							$('#formId').submit();
						},1000);
					}
				},'json');
				layer.close(index);
			});
		}
		function addHost(){
			var host = $('#host').val(),
				user  = $('#user').val(),
				passord  = $('#passord').val(),
				group  = $('#group').val(),
				connect  = $('#connect').val(),
				tip  = $('#tip').val();
			if($.trim(host) == ''){
				return layer.msg('ip不能为空。',so.default),!1;
			}
			if($.trim(user) == ''){
				return layer.msg('系统用户不能为空。',so.default),!1;
			}
			var load = layer.load();
			$.post('${basePath}/config/add.shtml',{host:host,user:user,passord:passord,group:group,connect:connect,tip:tip},function(result){
				layer.close(load);
				if(result && result.status != 200){
					return layer.msg(result.message,so.default),!1;
				}
				layer.msg('添加成功。');
				setTimeout(function(){
					$('#formId').submit();
				},1000);
			},'json');
		}
	</script>
  </body>
</html>
